package plugins

import (
	"gorm_learn/conn"
	"log"
)
import "gorm.io/plugin/prometheus"

func Register() {
	db := conn.GetDB()
	err := db.Use(prometheus.New(prometheus.Config{
		DBName:          "db1", // use `DBName` as metrics label
		RefreshInterval: 15,    // Refresh metrics interval (default 15 seconds)
		//PushAddr:        "localhost", // push metrics if `PushAddr` configured
		StartServer:    true, // start http server to expose metrics
		HTTPServerPort: 8080, // configure http server port, default port 8080 (if you have configured multiple instances, only the first `HTTPServerPort` will be used to start server)
		MetricsCollector: []prometheus.MetricsCollector{
			&prometheus.MySQL{
				VariableNames: []string{"Threads_running"},
			},
		}, // user defined metrics
	}))

	if err != nil {
		log.Fatalln("Error when use plugin!")
		return
	}
}
